<template>
  <view class="Page">
    <!-- 企业端我的 -->
    <mineNavbar :styleData="styleData">
      <view class="babbarTop">
        <image src="http://wangxinbao.oss-cn-beijing.aliyuncs.com/2024/04/11/9cc83d89695f4b0abb5ac693d666be1f.png"
          style="width: 122rpx; height: 40rpx" />
      </view>
    </mineNavbar>
    <view class="scroll">
      <view class="mine">
        <view class="contain">
          <view class="t-card">
            <view class="top">
              <!-- v-if="isLogin" -->
              <view class="leftBox" v-if="isLogin === 2">
                <view class="desc" @click="handleGoEnterise">
                  {{ (userInfo && userInfo.fullName) || "点击设置企业名称" }}
                </view>
                <view class="desc-1" @click="handleGoLocation">
                  {{ (userInfo && userInfo.storeName) || "" }}
                  <image
                    src="http://wangxinbao.oss-cn-beijing.aliyuncs.com/2024/04/03/da41b977f14c45dbbe3fbd3677b327be.png"
                    mode="" />
                </view>
              </view>
              <navigator v-else-if="isLogin === 1" url="/subPage/enterprise/mine/details/enterpriseData"
                hover-class="none" class="leftBox">
                <view class="desc"> 点击设置企业资料 </view>
                <!-- <view class="desc-1"> 请尽快完善资料</view> -->
              </navigator>
              <navigator v-else url="/pages/recruit/login/index" hover-class="none" class="leftBox">
                <view class="desc"> 点击登录 </view>
                <view class="desc-1"> 登录体验全部功能</view>
              </navigator>

              <view class="rightBox">
                <image class="" :src="userInfo.url || ''" mode="aspectFit|aspectFill|widthFix" lazy-load="false"
                  binderror="" bindload="" />
              </view>
            </view>

            <view class="numP">
              <view @click="toSwitch('pages/tabbarChange/thirdlyPage/index')">
                <text class="position">岗位</text>
                <text class="number">{{
                  (numDetails && numDetails.positionQuantity) || "0"
                }}</text>
              </view>

              <navigator url="/subPage/enterprise/mine/collectList/index" hover-class="none" style="display: block">
                <text class="position">收藏</text>
                <text class="number">{{
                  (numDetails && numDetails.collectQuantity) || "0"
                }}</text>
              </navigator>

              <view @click="toSwitch('pages/tabbarChange/thirdlyPage/index')">
                <text class="position">申请</text>
                <text class="number">{{
                  (numDetails && numDetails.applyForQuantity) || "0"
                }}</text>
              </view>
            </view>
          </view>

          <view class="vipBox" @click="toPath('subPage/enterprise/mine/details/enterpriseVip')">
            <view class="content">
              <view class="image">
                <image class="image" src="@/static/images/emterpriseMineImg/vip.png" mode="aspectFit|aspectFill|widthFix"
                  lazy-load="false" binderror="" bindload="" />
              </view>

              <view class="user" selectable="false" space="false" decode="false">
                您好，尊贵的薪马马企业VIP用户
              </view>

              <view class="look"> 查看 </view>
            </view>
          </view>
        </view>

        <view class="middle-b">
          <view class="title"> 常用功能 </view>

          <view class="box">
            <view class="item" v-for="(item, index) in middleList" :key="item.id" @click="toPath(item.path)">
              <view class="imageIcon">
                <image class="imageIcon" :src="item.icon" mode="aspectFit|aspectFill|widthFix" lazy-load="false"
                  binderror="" bindload="" />
              </view>

              <text class="text">{{ item.name }}</text>
            </view>
          </view>
        </view>

        <view class="middle-b">
          <view class="title"> 其他功能 </view>

          <view class="box">
            <view class="item" v-for="item in orderList" :key="item.id" style="width: 25%" @click="orderToPath(item)">
              <view class="imageIcon">
                <image class="imageIcon" :src="item.icon" mode="aspectFit|aspectFill|widthFix" lazy-load="false"
                  binderror="" bindload="" />
              </view>

              <text class="text">{{ item.name }}</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="logOut" @click="handleGoLogin"> 退出登录 </view>
  </view>
</template>

<script>
import { getSiteStore } from "@/api/pages/mine.js";
import { getWxUserInfo, getQuantitys } from "@/api/subPage/mine.js";
import { getToken } from "@/utils/auth";
// import { mapState } from "vuex";
export default {
  components: {},

  data() {
    return {
      styleData: {
        background: "#fff6ea",
        TextColor: "#000000",
        show: false,
      },

      middleList: [
        {
          name: "企业资料",
          icon: require("@/static/images/emterpriseMineImg/qy.png"),
          path: "subPage/enterprise/mine/details/enterpriseData",
          id: 1,
        },
        {
          name: "财务管理",
          icon: require("@/static/images/emterpriseMineImg/cw.png"),
          path: "subPage/enterprise/mine/details/finance",
          id: 2,
        },
        {
          name: "结算管理",
          path: "subPage/enterprise/mine/details/settlement",
          icon: require("@/static/images/emterpriseMineImg/js.png"),
          id: 3,
        },
        {
          name: "企业认证",
          path: "subPage/enterprise/mine/details/approve",
          icon: require("@/static/images/emterpriseMineImg/rz.png"),
          id: 4,
        },
        {
          name: "我的积分",
          path: "subPage/enterprise/mine/details/integral",
          icon: require("@/static/images/emterpriseMineImg/jf.png"),
          id: 5,
        },
        {
          name: "门店托管",
          path: "subPage/enterprise/mine/details/trusteeship",
          icon: require("@/static/images/emterpriseMineImg/tg.png"),
          id: 6,
        },
      ],

      orderList: [
        {
          name: "关于我们",
          icon: require("@/static/images/emterpriseMineImg/gy.png"),
          path: "subPage/enterprise/mine/details/aboutUs",
          id: 12,
        },
        {
          name: "帮助文档",
          icon: require("@/static/images/emterpriseMineImg/bz.png"),
          path: "subPage/enterprise/mine/details/helpText",
          id: 56,
        },
        {
          name: "法务咨询",
          icon: require("@/static/images/emterpriseMineImg/fw.png"),
          id: 123,
        },
        {
          name: "人才库",
          icon: require("@/static/images/emterpriseMineImg/rc.png"),
          path: "subPage/enterprise/mine/details/talentPool",
          id: 232,
        },
        {
          name: "切为求职者",
          icon: require("@/static/images/emterpriseMineImg/qh.png"),
          id: 23,
        },

        {},
        {},
        {},
      ],

      isLogin: 0, // 是否登录
      //用户信息
      userInfo: {
        wxUserId: "", // 求职者微信用户编号
        wxUserName: "", // 用户名
        wxAvatar: "", // 头像
        wxMobile: "", // 电话
        wxSex: "", // 性别（0男 1女 2未知）
        verifyStatus: "", // 实名认证状态 (0未实名 1已实名)
      },

      numDetails: {},
      loginStatus: 0
    };
  },
  computed: {},
  watch: {},
  onLoad(options) { },
  onShow() { },
  // onReady() {},
  created() { },
  mounted() {
    this.getUserInfoAPI();
    // this.getLoginStatus()
  },
  methods: {
    // 获取登录状态
    // getLoginStatus() {
    //   this.loginStatus = JSON.parse(uni.getStorageSync('loginStatus'))
    // },
    // 跳转门店位置页面
    handleGoLocation() {
      // 获取门店信息
      // getSiteStore().then((res) => {
      //   let storeObj = res.data[0]
      //   console.log(storeObj);
      //   // 打开手机安装的地图app
      //   uni.openLocation({
      //     latitude: Number(storeObj.latitude),
      //     longitude: Number(storeObj.longitude),
      //     name: storeObj.storeName,
      //     address: storeObj.detailedAddress,
      //     scale: 18,
      //   });
      // });
      uni.navigateTo({ url: '/subPage/enterprise/post/mapLocation/index' })
    },
    // 获取用户信息
    getUserInfoAPI() {
      getWxUserInfo()
        .then((res) => {
          if (res.code === 200) {
            this.userInfo = res.data;
            this.isLogin = 2;
            this.getQuantity();
          }
        })
        .catch((err) => {
          console.log(err);
          if (err === 10001) {
            this.isLogin = 1;
          }
        });
    },

    // 跳转完善企业资料
    handleGoEnterise() {
      if (!this.userInfo.fullName) {
        uni.navigateTo({
          url: '/subPage/enterprise/mine/details/enterpriseData'
        })
      }
    },

    async getQuantity() {
      const { code, data } = await getQuantitys();

      if (code === 200) this.numDetails = data;
    },

    // 退出登录
    handleGoLogin() {
      let that = this;
      uni.showModal({
        title: "提示",
        content: "确定退出系统吗？",
        cancelText: "取消",
        confirmText: "确定",
        success: function (res) {
          that.$store.dispatch("LogOut").then(() => {
            if (res.confirm) {
              uni.setStorageSync('loginStatus', 0)
              that.isLogin = 0;
              that.numDetails = null;
              that.userInfo = {
                wxUserId: "", // 求职者微信用户编号
                wxUserName: "", // 用户名
                wxAvatar: "", // 头像
                wxMobile: "", // 电话
                wxSex: "", // 性别（0男 1女 2未知）
                verifyStatus: "", // 实名认证状态 (0未实名 1已实名)
              };
              uni.navigateTo({
                url: "/pages/recruit/login/index",
              });
            }
          });
        },
      });
    },

    toPath(path) {
      console.log(path);
      uni.navigateTo({
        url: `/${path}`,
      });
    },

    toSwitch(path) {
      uni.switchTab({
        url: `/${path}`,
      });
    },

    async orderToPath(item) {
      if (item.name === "切为求职者") {
        this.$store.commit("setUserType", "1");

        // 切换登录
        if (getToken()) {
          const type = this.$store.state.userType;
          this.$store.dispatch("CutLogin", { type });
        }

        // 切换页面
        if (this.$store.state.userType === "1") {
          wx.setTabBarItem({
            index: 0,
            text: "首页",
            iconPath: "static/images/recruit/company-sele(1).png",
            selectedIconPath: "static/images/recruit/company-sele.png",
          });
          wx.setTabBarItem({
            index: 1,
            text: "岗位",
            iconPath: "static/images/recruit/company-sele(3).png",
            selectedIconPath: "static/images/recruit/company-sele(2).png",
          });
          wx.setTabBarItem({
            index: 2,
            text: "消息",
            iconPath: "static/images/recruit/company-sele(5).png",
            selectedIconPath: "static/images/recruit/company-sele(4).png",
          });
          wx.setTabBarItem({
            index: 3,
            text: "我的",
            iconPath: "static/images/recruit/company-sele(9).png",
            selectedIconPath: "static/images/recruit/company-sele(8).png",
          });
        } else {
          wx.setTabBarItem({
            index: 0,
            text: "首页",
            iconPath: "static/images/recruit/company-sele(1).png",
            selectedIconPath: "static/images/recruit/company-sele.png",
          });
          wx.setTabBarItem({
            index: 1,
            text: "人才",
            iconPath: "static/images/recruit/company-sele(7).png",
            selectedIconPath: "static/images/recruit/company-sele(6).png",
          });
          wx.setTabBarItem({
            index: 2,
            text: "岗位",
            iconPath: "static/images/recruit/company-sele(3).png",
            selectedIconPath: "static/images/recruit/company-sele(2).png",
          });
          wx.setTabBarItem({
            index: 3,
            text: "我的",
            iconPath: "static/images/recruit/company-sele(9).png",
            selectedIconPath: "static/images/recruit/company-sele(8).png",
          });
        }
      }

      if (item.name === "法务咨询") {
        uni.openCustomerServiceChat({
          extInfo: {
            url: "https://work.weixin.qq.com/kfid/kfcc768abd5fda6c86e",
          }, //客服跳转链接
          corpId: "wwbbe910ab168f836e", // 企业微信id
          success(res) {
            console.log(res);
          },
          fail(err) {
            console.log(err);
          },
        });
      }

      if (item.path === undefined) return;
      uni.navigateTo({
        url: `/${item.path}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.Page {
  height: 102vh;
  overflow: hidden;

  .babbarTop {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    margin-left: 32rpx;
  }
}

.scroll {
  display: flex;
  flex-direction: column;

  overflow: hidden;

  .mine {
    display: flex;
    align-items: center;
    flex-direction: column;
    background-color: #f9f9f9;

    .contain {
      position: relative;
      background-color: #fff6ea;

      width: 100%;
      display: flex;
      justify-content: center;
      height: 350rpx;

      .t-card {
        position: absolute;
        border-radius: 24rpx;
        z-index: 10;
        width: 706rpx;
        height: 252rpx;
        background: #ffffff;

        .top {
          width: 702rpx;
          display: flex;

          justify-content: space-between;
          margin-top: 42rpx;

          .leftBox {
            margin-left: 32rpx;

            .desc {
              font-weight: 700;
              font-size: 36rpx;
              color: #000000e0;
              letter-spacing: 0;
            }

            .desc-1 {
              opacity: 0.64;

              font-weight: 500;
              font-size: 24rpx;
              color: #000000a3;
              letter-spacing: 0;
              margin-right: 4rpx;

              image {
                width: 12rpx;
                height: 12rpx;
              }
            }
          }

          .rightBox {
            margin-right: 32rpx;
            width: 92rpx;
            height: 90rpx;
            background-color: #ffffff;
            border-radius: 50%;

            image {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
        }

        .numP {
          display: flex;
          justify-content: start;
          justify-content: space-evenly;
          margin-top: 45rpx;
          width: 100%;

          .position {
            opacity: 0.64;

            font-weight: 500;
            font-size: 24rpx;
            color: #000000a3;
            letter-spacing: 0;
          }

          .number {
            font-weight: 700;
            font-size: 36rpx;
            color: #000000e0;
            letter-spacing: 0;
            margin-left: 6rpx;
          }

          .rog {}
        }
      }

      .vipBox {
        position: absolute;
        top: 158rpx;
        width: 702rpx;
        height: 189rpx;
        background-image: linear-gradient(180deg,
            #0f0f0f 0%,
            #141414 61%,
            #504b45 100%);
        border-radius: 24rpx;
        z-index: 1;
        display: flex;
        align-items: flex-end;

        .content {
          display: flex;
          width: 702rpx;
          height: 95rpx;
          align-items: center;
          justify-content: space-evenly;

          .image {
            padding-left: 10rpx;
            width: 40rpx;
            height: 40rpx;
          }

          .user {
            height: 40rpx;
            line-height: 40rpx;

            font-weight: 600;
            font-size: 28rpx;
            color: #ffe6c4;
          }

          .look {
            width: 145rpx;
            height: 55rpx;
            line-height: 56rpx;
            border: 1rpx solid #fff0db;
            border-radius: 28rpx;
            background-color: #fff0db;
            font-weight: 600;
            font-size: 24rpx;
            color: #000000e0;
            text-align: center;
          }
        }
      }
    }

    .middle-b {
      width: 702rpx;
      height: 418rpx;
      background: #ffffff;
      border-radius: 24rpx;
      margin-top: 24rpx;

      .title {
        padding-top: 24rpx;
        padding-left: 32rpx;
        font-weight: 700;
        font-size: 28rpx;
        color: #000000;
        letter-spacing: 0;
      }

      .imageIcon {
        width: 56rpx;
        height: 56rpx;
        margin-bottom: 16rpx;
      }

      .box {
        display: flex;
        justify-content: space-evenly;
        flex-wrap: wrap;
        margin-top: 45rpx;
        margin-left: 20rpx;
        margin-right: 20rpx;

        .item {
          width: 33.3%;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          margin-bottom: 58rpx;
        }

        .text {
          font-weight: 500;
          font-size: 24rpx;
          color: #000000;
          opacity: 0.64;
        }
      }
    }
  }
}

.logOut {
  width: 96rpx;
  height: 80rpx;
  line-height: 80rpx;
  margin: 20rpx auto;
  font-weight: 500;
  font-size: 24rpx;
  color: #00000073;

  text-align: center;
}
</style>
